package com.chinabank.dao.impl;

import java.util.List;

import org.hibernate.Session;
import org.springframework.stereotype.Repository;

import com.chinabank.dao.DemandReportDao;
import com.chinabank.model.Account;
import com.chinabank.model.DemandReport;

@Repository(value = "demandReportDao")
public class DemandReportDaoImpl extends BaseDaoImpl<DemandReport> implements
		DemandReportDao {

	public List<DemandReport> getAllDemandReportsAsApplier(Account account) {
		Session session = this.getSessionFactory().getCurrentSession();
		String hqlString = "select DemandReport dr " + "where dr.applier.id=?";
		List<DemandReport> demandReports = (List<DemandReport>) session
				.createQuery(hqlString).setLong(0, account.getId()).list();
		return demandReports;
	}

	@Override
	public List<DemandReport> getAllDemandReportsAsReviewer(Account account) {
		Session session = this.getSessionFactory().getCurrentSession();
		String hqlString = "select dr from DemandReport dr, Assignment assmt, "
				+ "assmt.screeners screener where assmt.demandReport.id=dr.id "
				+ "and screener.id=?";
		List<DemandReport> demandReports = (List<DemandReport>) session
				.createQuery(hqlString).setLong(0, account.getId()).list();
		return demandReports;
	}
}